{% extends "app/base_site.html" %}

{% block title %} 音频管理 {% endblock title %}

{% block stylesheets %}
  {{ block.super }}
<style>
    .xc_audio-container {
        /*background: #f5f7fa;*/
    }
    
    .xc_modern-card {
        background: white;
        border-radius: 6px;
        padding: 10px 14px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06);
        margin-bottom: 12px;
    }
    
    .xc_page-header {
        display: flex;
        justify-content: flex-start !important;
        align-items: center;
        padding: 4px 0;
        margin-bottom: 8px;
        min-height: 32px;
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .xc_page-title {
        display: flex;
        align-items: center;
        font-size: 18px;
        font-weight: 400;
        flex-shrink: 0;
    }
    
    .xc_page-title i {
        margin-right: 6px;
        font-size: 16px;
        color: #3b82f6;
    }
    
    .xc_header-right {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-wrap: nowrap;
        height: 28px;
    }
    
    .xc_header-actions {
        display: flex;
        align-items: center;
        gap: 6px;
        height: 28px;
    }
    
    .xc_loading-spinner {
        display: inline-block;
        width: 12px;
        height: 12px;
        border: 2px solid #e5e7eb;
        border-top: 2px solid #3b82f6;
        border-radius: 50%;
        animation: xc_spin 1s linear infinite;
        margin-right: 5px;
    }
    
    @keyframes xc_spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    
    .xc_loading-text {
        color: #6b7280;
        font-size: 12px;
    }
    
    .xc_btn-modern {
        padding: 0 10px;
        font-size: 12px;
        font-weight: 400;
        border-radius: 3px;
        border: 1px solid #d1d5db;
        background: white;
        color: #374151;
        cursor: pointer;
        transition: all 0.2s;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        white-space: nowrap;
        text-decoration: none;
        height: 28px;
        line-height: 1;
        box-sizing: border-box;
    }
    
    .xc_btn-modern:hover {
        background: #f9fafb;
        border-color: #3b82f6;
        color: #3b82f6;
    }
    
    .xc_btn-secondary {
        background: white;
        color: #6b7280;
        border: 1px solid #d1d5db;
    }
    
    .xc_btn-secondary:hover {
        background: #f9fafb;
        color: #374151;
        border-color: #9ca3af;
    }
    
    .xc_btn-primary {
        background: #3b82f6;
        color: white;
        border: 1px solid #3b82f6;
    }
    
    .xc_btn-primary:hover {
        background: #2563eb;
        border-color: #2563eb;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    }

    .xc_audio-player-compact {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 0;
        background: none;
        border: none;
        height: 32px;
        line-height: 1;
        box-sizing: border-box;
        flex-shrink: 0;
    }
    
    .xc_audio-player-compact-icon {
        color: #3b82f6;
        font-size: 12px;
        flex-shrink: 0;
        line-height: 1;
    }
    
    .xc_audio-player-compact audio {
        height: 26px;
        width: 180px;
        margin: 0;
        padding: 0;
        display: block;
        border: none;
        outline: none;
    }
    
    .xc_table-container {
        overflow-x: auto;
        border-radius: 6px;
        border: 1px solid #e5e7eb;
    }
    
    .xc_table {
        width: 100%;
        border-collapse: collapse;
        font-size: 12px;
    }
    
    .xc_table-header {
        background: #fafafa;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .xc_table-header th {
        padding: 10px 12px;
        text-align: left;
        font-weight: 500;
        color: #374151;
        font-size: 12px;
        white-space: nowrap;
    }
    
    .xc_table-body tr {
        border-bottom: 1px solid #f3f4f6;
        transition: background 0.2s;
    }
    
    .xc_table-body tr:last-child {
        border-bottom: none;
    }
    
    .xc_table-body tr:hover {
        background: #f9fafb;
    }
    
    .xc_table-body td {
        padding: 10px 12px;
        color: #374151;
        vertical-align: middle;
    }
    
    .xc_audio-id {
        display: inline-block;
        padding: 2px 6px;
        background: #f3f4f6;
        border: 1px solid #e5e7eb;
        border-radius: 3px;
        font-size: 11px;
        color: #6b7280;
        font-family: monospace;
    }
    
    .xc_audio-code {
        display: inline-block;
        padding: 3px 8px;
        background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
        border: 1px solid #6ee7b7;
        border-radius: 3px;
        font-size: 11px;
        color: #065f46;
        font-family: monospace;
        font-weight: 600;
        box-shadow: 0 1px 3px rgba(22, 159, 133, 0.2);
    }
    
    .xc_audio-name {
        font-weight: 500;
        color: #374151;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    .xc_audio-icon {
        color: #169F85;
        font-size: 14px;
    }
    
    .xc_time-text {
        color: #6b7280;
        font-size: 11px;
    }
    
    .xc_action-group {
        display: flex;
        gap: 4px;
        align-items: center;
    }
    
    .xc_btn-action {
        padding: 3px 8px;
        font-size: 11px;
        border-radius: 3px;
        border: 1px solid #d1d5db;
        background: white;
        color: #6b7280;
        cursor: pointer;
        transition: all 0.2s;
        display: inline-flex;
        align-items: center;
        gap: 3px;
        white-space: nowrap;
    }
    
    .xc_btn-action:hover {
        background: #f9fafb;
        border-color: #3b82f6;
        color: #3b82f6;
    }
    
    .xc_btn-action.delete:hover {
        background: #fef2f2;
        border-color: #ef4444;
        color: #ef4444;
    }
    
    .xc_pagination {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 8px;
        padding: 16px 0;
        background: white;
        border-radius: 6px;
    }
    
    .xc_page-btn {
        min-width: 36px;
        height: 36px;
        padding: 0 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1px solid #d1d5db;
        background: white;
        color: #6b7280;
        border-radius: 5px;
        cursor: pointer;
        font-size: 13px;
        transition: all 0.2s;
        text-decoration: none;
    }
    
    .xc_page-btn:hover:not(.active) {
        border-color: #3b82f6;
        color: #3b82f6;
    }
    
    .xc_page-btn.active {
        background: #3b82f6;
        color: white;
        border-color: #3b82f6;
    }
    
    .xc_page-info {
        font-size: 13px;
        color: #9ca3af;
        margin: 0 8px;
    }
    
    .xc_empty-state {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
        padding: 80px 20px;
        min-height: 400px;
        color: #9ca3af;
    }
    
    .xc_empty-state i {
        font-size: 64px;
        color: #d1d5db;
        margin-bottom: 16px;
        opacity: 0.6;
    }
    
    .xc_empty-state p {
        font-size: 14px;
        margin: 0;
        color: #6b7280;
    }
    
    .right_col {
        background: #f5f7fa !important;
    }
    
    /* 弹窗样式 */
    .xc_modal-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        animation: xc_fadeIn 0.2s ease;
    }
    
    .xc_modal-overlay.active {
        display: block;
    }
    
    @keyframes xc_fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    .xc_modal-container {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: white;
        border-radius: 8px;
        width: 90%;
        max-width: 650px;
        max-height: 80vh;
        display: flex;
        flex-direction: column;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
        animation: xc_slideIn 0.3s ease;
    }
    
    @keyframes xc_slideIn {
        from {
            transform: translate(-50%, -48%);
            opacity: 0;
        }
        to {
            transform: translate(-50%, -50%);
            opacity: 1;
        }
    }
    
    .xc_modal-header {
        padding: 14px 18px;
        border-bottom: 1px solid #e5e7eb;
        background: linear-gradient(to bottom, #fafafa 0%, #ffffff 100%);
        border-radius: 8px 8px 0 0;
        position: relative;
    }
    
    .xc_modal-title {
        font-size: 16px;
        font-weight: 600;
        color: #1f2937;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .xc_modal-title i {
        color: #3b82f6;
    }
    
    .xc_modal-close {
        position: absolute;
        top: 12px;
        right: 16px;
        width: 30px;
        height: 30px;
        border: none;
        background: #f3f4f6;
        color: #6b7280;
        font-size: 20px;
        line-height: 1;
        cursor: pointer;
        padding: 0;
        border-radius: 4px;
        transition: all 0.2s;
    }
    
    .xc_modal-close:hover {
        background: #e5e7eb;
        color: #374151;
        transform: rotate(90deg);
    }
    
    .xc_modal-body {
        flex: 1;
        padding: 18px 20px;
        overflow-y: auto;
    }
    
    .xc_form-group {
        margin-bottom: 14px;
    }
    
    .xc_form-label {
        display: block;
        font-size: 13px;
        font-weight: 500;
        color: #374151;
        margin-bottom: 6px;
    }
    
    .xc_form-label .required {
        color: #ef4444;
        margin-left: 2px;
    }
    
    .xc_form-input {
        width: 100%;
        padding: 8px 12px;
        font-size: 13px;
        border: 1px solid #d1d5db;
        border-radius: 4px;
        transition: all 0.2s;
        height: 36px;
    }
    
    .xc_form-input:focus {
        outline: none;
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }
    
    .xc_form-input:disabled {
        background: #f3f4f6;
        color: #9ca3af;
        cursor: not-allowed;
    }
    
    .xc_form-file {
        padding: 0 10px;
        font-size: 13px;
        cursor: pointer;
        display: flex;
        align-items: center;
        height: 36px;
        line-height: 36px;
        border: 1px solid #d1d5db;
        border-radius: 4px;
    }
    
    .xc_form-file::file-selector-button {
        padding: 5px 12px;
        margin-right: 10px;
        font-size: 12px;
        color: #374151;
        background: #f3f4f6;
        border: 1px solid #d1d5db;
        border-radius: 4px;
        cursor: pointer;
        transition: all 0.2s;
        line-height: 1.2;
    }
    
    .xc_form-file::file-selector-button:hover {
        background: #e8f4f1;
        border-color: #10b981;
    }
    
    .xc_form-help {
        font-size: 12px;
        color: #6b7280;
        margin-top: 5px;
    }
    
    .xc_modal-footer {
        padding: 14px 18px;
        border-top: 1px solid #e5e7eb;
        text-align: right;
        background: linear-gradient(to top, #fafafa 0%, #ffffff 100%);
        border-radius: 0 0 8px 8px;
    }
    
    .xc_modal-btn {
        padding: 7px 18px;
        font-size: 13px;
        border-radius: 4px;
        border: none;
        cursor: pointer;
        margin-left: 10px;
        transition: all 0.2s;
        font-weight: 500;
    }
    
    .xc_modal-btn-cancel {
        background: #f3f4f6;
        color: #6b7280;
    }
    
    .xc_modal-btn-cancel:hover {
        background: #e5e7eb;
        color: #374151;
    }
    
    .xc_modal-btn-submit {
        background: #3b82f6;
        color: white;
        box-shadow: 0 1px 3px rgba(59, 130, 246, 0.3);
    }
    
    .xc_modal-btn-submit:hover {
        background: #2563eb;
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
        transform: translateY(-1px);
    }

    @media (max-width: 1200px) {
        .xc_btn-modern {
            padding: 3px 8px;
            font-size: 11px;
        }

        .xc_page-title {
            font-size: 16px;
        }
    }
    
    @media (max-width: 768px) {
        .xc_page-header {
            flex-wrap: wrap;
            gap: 8px;
        }
        
        .xc_header-right {
            width: 100%;
            justify-content: flex-start;
        }
        
        .xc_audio-player-container {
            flex-direction: column;
        }
        
        .xc_action-group {
            flex-wrap: wrap;
        }
    }
</style>
{% endblock stylesheets %}

{% block content %}
<div class="right_col" role="main">
    <div class="row">
        <div class="col-md-12">
            <div class="x_panel">
                <!-- xc page start -->
                <div class="xc_audio-container">
                    <div class="xc_modern-card">
                        <div class="xc_page-header">
                            <div class="xc_page-title">
                                <i class="fa fa-music"></i>
                                音频管理
                            </div>
                            <div class="xc_audio-player-compact">
                                <i class="fa fa-volume-up xc_audio-player-compact-icon"></i>
                                <audio id="top_audio" controls>
                                    浏览器不支持音频播放
                                </audio>
                            </div>
                            <div class="xc_header-actions">
                                <button onclick="openAudioModal('add')" class="xc_btn-modern xc_btn-secondary">
                                    <i class="fa fa-plus"></i> 添加
                                </button>
                                <button class="xc_btn-modern xc_btn-secondary" onclick="window.location.reload()">
                                    <i class="fa fa-refresh"></i> 刷新
                                </button>
                            </div>
                            <div>
                                <span id="top_loading" style="display: none;">
                                    <span class="xc_loading-spinner"></span>
                                    <span class="xc_loading-text">加载中...</span>
                                </span>
                                <span id="top_msg"></span>
                            </div>
                        </div>

                        {% if pageData.count > 0 %}
                        <div class="xc_table-container">
                            <table class="xc_table">
                                <thead class="xc_table-header">
                                    <tr>
                                        <th style="width: 80px;">ID</th>
                                        <th style="width: 160px;">编号</th>
                                        <th>名称</th>
                                        <th style="width: 160px;">更新时间</th>
                                        <th style="width: 180px;">操作</th>
                                    </tr>
                                </thead>
                                <tbody class="xc_table-body">
                                    {% for d in data %}
                                    <tr>
                                        <td>
                                            <span class="xc_audio-id">{{ d.id }}</span>
                                        </td>
                                        <td>
                                            <!--<span class="xc_audio-code">{{ d.code }}</span>-->
                                            <span>{{ d.code }}</span>
                                        </td>
                                        <td>
                                            <!--<div class="xc_audio-name">
                                                <i class="fa fa-file-audio-o xc_audio-icon"></i>
                                                {{ d.name }}
                                            </div>-->
                                            <span>{{ d.name }}</span>
                                        </td>
                                        <td>
                                            <span class="xc_time-text">{{ d.last_update_time|date:"Y-m-d H:i:s" }}</span>
                                        </td>
                                        <td>
                                            <div class="xc_action-group">
                                                <button onclick="openAudioModal('edit', '{{ d.code }}')" class="xc_btn-action" title="编辑">
                                                    <i class="fa fa-edit"></i> 编辑
                                                </button>
                                                <button onclick="f_play('{{ d.audio_path }}')" class="xc_btn-action" title="播放">
                                                    <i class="fa fa-play"></i> 播放
                                                </button>
                                                <button onclick="f_del('{{ d.code }}')" class="xc_btn-action delete" title="删除">
                                                    <i class="fa fa-trash-o"></i> 删除
                                                </button>
                                            </div>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                        {% else %}
                        <div class="xc_empty-state">
                            <i class="fa fa-music"></i>
                            <p>暂无音频数据</p>
                        </div>
                        {% endif %}
                    </div>

                    {% if pageData.count > 0 %}
                    <div class="xc_pagination">
                        <div class="xc_page-info">
                            共 {{ pageData.page_num }} 页 / {{ pageData.count }} 条
                        </div>
                        {% for d in pageData.pageLabels %}
                            {% if d.cur == 1 %}
                                <div class="xc_page-btn active">{{ d.name }}</div>
                            {% else %}
                                <a href="/audio/index?p={{ d.page }}&ps={{ pageData.page_size }}" class="xc_page-btn">{{ d.name }}</a>
                            {% endif %}
                        {% endfor %}
                    </div>
                    {% endif %}
                </div>
                <!-- xc page end -->
            </div>
        </div>
    </div>
</div>

<!-- 音频弹窗 -->
<div class="xc_modal-overlay" id="audioModal">
    <div class="xc_modal-container">
        <div class="xc_modal-header">
            <div class="xc_modal-title">
                <i class="fa fa-music"></i>
                <span id="modalTitle">添加音频</span>
            </div>
            <button class="xc_modal-close" onclick="closeAudioModal()">×</button>
        </div>
        <div class="xc_modal-body">
            <form id="audioForm" enctype="multipart/form-data">
                <input type="hidden" id="input_handle" name="handle" value="add">
                <input type="hidden" id="input_code" name="code" value="">
                
                <div class="xc_form-group">
                    <label class="xc_form-label">音频编号</label>
                    <input type="text" id="display_code" class="xc_form-input" disabled>
                </div>
                
                <div class="xc_form-group">
                    <label class="xc_form-label">音频名称<span class="required">*</span></label>
                    <input type="text" id="input_name" name="name" class="xc_form-input" placeholder="请输入音频名称" required>
                </div>
                
                <div class="xc_form-group" id="fileGroup">
                    <label class="xc_form-label">音频文件<span class="required">*</span></label>
                    <input type="file" id="input_file" name="file" class="xc_form-file" accept="audio/wav,audio/mpeg">
                    <div class="xc_form-help">支持WAV、MP3格式，文件大小不超过20M</div>
                </div>
                
                <div class="xc_form-group" id="pathGroup" style="display: none;">
                    <label class="xc_form-label">音频文件路径</label>
                    <input type="text" id="input_path" class="xc_form-input" disabled>
                </div>
                
                <div class="xc_form-group">
                    <label class="xc_form-label">扩展参数</label>
                    <input type="text" id="input_extend_params" name="extend_params" class="xc_form-input" placeholder="可选">
                </div>
                
                <div class="xc_form-group">
                    <label class="xc_form-label">备注</label>
                    <input type="text" id="input_remark" name="remark" class="xc_form-input" placeholder="可选">
                </div>
            </form>
        </div>
        <div class="xc_modal-footer">
            <button class="xc_modal-btn xc_modal-btn-cancel" onclick="closeAudioModal()">取消</button>
            <button class="xc_modal-btn xc_modal-btn-submit" onclick="submitAudioForm()">提交</button>
        </div>
    </div>
</div>
{% endblock content %}

{% block javascripts %}
  {{ block.super }}

<script>
    let ele_top_loading = $("#top_loading");
    let ele_top_msg = $("#top_msg");
    let eleAudioPlayer = document.querySelector("#top_audio");
    let uploadAudioDir_www = '{{ uploadAudioDir_www }}';
    let currentHandle = 'add';
    let currentCode = '';

    // ============ 弹窗功能 ============
    function generateAudioCode() {
        let randomNum = Math.floor(Math.random() * 9000) + 1000;
        let chars = '0123456789abcdef';
        let randomStr = '';
        for(let i = 0; i < 6; i++) {
            randomStr += chars.charAt(Math.floor(Math.random() * chars.length));
        }
        return 'audio' + randomNum + randomStr;
    }

    function openAudioModal(handle, code = '') {
        currentHandle = handle;
        currentCode = code;
        
        $('#input_handle').val(handle);
        $('#audioForm')[0].reset();
        
        if (handle === 'add') {
            $('#modalTitle').text('添加音频');
            let newCode = generateAudioCode();
            $('#input_code').val(newCode);
            $('#display_code').val(newCode);
            $('#input_name').val('');
            $('#input_extend_params').val('');
            $('#input_remark').val('');
            $('#fileGroup').show();
            $('#pathGroup').hide();
            $('#input_file').prop('disabled', false);
        } else {
            $('#modalTitle').text('编辑音频');
            loadAudioData(code);
        }
        
        $('#audioModal').addClass('active');
    }

    function closeAudioModal() {
        $('#audioModal').removeClass('active');
        currentHandle = 'add';
        currentCode = '';
    }

    function loadAudioData(code) {
        ele_top_loading.show();
        $.ajax({
            url: '/audio/openInfo',
            type: 'get',
            data: {code: code},
            dataType: 'json',
            success: function(res) {
                ele_top_loading.hide();
                
                if(res.code === 1000 && res.info) {
                    let audio = res.info;
                    
                    $('#input_code').val(audio.code);
                    $('#display_code').val(audio.code);
                    $('#input_name').val(audio.name);
                    $('#input_extend_params').val(audio.extend_params || '');
                    $('#input_remark').val(audio.remark || '');
                    $('#input_path').val(audio.audio_path || '');
                    
                    $('#fileGroup').hide();
                    $('#pathGroup').show();
                    $('#input_file').prop('disabled', true);
                } else {
                    myToast2025(res.msg || '音频不存在', 'error');
                    closeAudioModal();
                }
            },
            error: function() {
                ele_top_loading.hide();
                myToast2025('加载失败，请稍后重试', 'error');
                closeAudioModal();
            }
        });
    }

    function submitAudioForm() {
        let name = $('#input_name').val().trim();
        if (!name) {
            myToast2025('请输入音频名称', 'error');
            return;
        }
        
        if (currentHandle === 'add') {
            let fileInput = $('#input_file')[0];
            if (!fileInput.files || fileInput.files.length === 0) {
                myToast2025('请上传音频文件', 'error');
                return;
            }
            
            let file = fileInput.files[0];
            let fileSize = parseInt(file.size);
            let fileSizeM = parseInt(fileSize / 1024 / 1024);
            
            if (fileSizeM > 20) {
                myToast2025('音频文件不能超过20M: ' + fileSizeM + 'M', 'error');
                return;
            }
        }
        
        let formData = new FormData($('#audioForm')[0]);

        let url = currentHandle === 'add' ? '/audio/openAdd' : '/audio/openEdit';
        
        ele_top_loading.show();
        $.ajax({
            url: url,
            type: 'post',
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'json',
            success: function(res) {
                ele_top_loading.hide();
                
                if (res.code === 1000) {
                    myToast2025(res.msg, 'success', 1000);
                    setTimeout(function() {
                        closeAudioModal();
                        window.location.reload();
                    }, 1000);
                } else {
                    myToast2025(res.msg, 'error');
                }
            },
            error: function(xhr, status, error) {
                ele_top_loading.hide();
                console.error('AJAX错误:', {status: status, error: error, responseText: xhr.responseText});
                myToast2025('网络异常，请确定网络正常！', 'error');
            }
        });
    }

    // 点击遮罩层关闭
    $('#audioModal').click(function(e) {
        if (e.target === this) {
            closeAudioModal();
        }
    });

    // ESC键关闭
    $(document).keydown(function(e) {
        if (e.keyCode === 27 && $('#audioModal').hasClass('active')) {
            closeAudioModal();
        }
    });

    // ============ 原有功能 ============
    function f_del(code) {
        let ret = confirm("确认删除该音频吗？");
        if (!ret) return;
        
        ele_top_loading.show();
        $.ajax({
            url: '/audio/openDel',
            type: "post",
            async: true,
            data: {"code": code},
            dataType: "json",
            timeout: 0,
            error: function () {
                ele_top_loading.hide();
                myToast2025("网络异常，请确定网络正常！", "error");
            },
            success: function (res) {
                ele_top_loading.hide();
                if (1000 === res.code) {
                    myToast2025(res.msg, "success", 1000);
                    setTimeout(function() {
                        window.location.reload();
                    }, 1000);
                } else {
                    myToast2025(res.msg, "error");
                }
            }
        });
    }
    
    function f_play(audio_path) {
        // 确保路径拼接正确，处理可能的无效值
        if (!audio_path) {
            myToast2025('音频文件路径为空', 'error');
            return;
        }
        
        // 直接拼接，uploadAudioDir_www 已经包含末尾的 /
        let audio_url = uploadAudioDir_www + audio_path;
        
        console.log('=== 音频播放调试信息 ===');
        console.log('uploadAudioDir_www:', uploadAudioDir_www);
        console.log('audio_path:', audio_path);
        console.log('完整URL:', audio_url);
        
        try {
            if (!eleAudioPlayer.paused) {
                eleAudioPlayer.pause();
            }
            eleAudioPlayer.setAttribute("src", audio_url);
            
            // 监听音频加载错误
            eleAudioPlayer.onerror = function() {
                console.error('音频加载失败:', {
                    error: eleAudioPlayer.error,
                    src: eleAudioPlayer.src
                });
                myToast2025('音频加载失败，请检查文件是否存在: ' + audio_url, 'error');
            };
            
            eleAudioPlayer.play();
        } catch (e) {
            console.error("播放错误:", e);
            myToast2025("播放失败，请检查音频文件", "error");
        }
    }

    $(function() {
        ele_top_loading.hide();
    });
</script>

{% endblock javascripts %}
